<template>
  <div class="leave-apply">
    <el-card>
      <template #header>
        <div class="card-header">
          <span>请假申请</span>
          <el-button type="primary" @click="handleApply">申请请假</el-button>
        </div>
      </template>

      <!-- 请假记录列表 -->
      <el-table :data="leaveRecords" style="width: 100%" border stripe>
        <el-table-column prop="type" label="请假类型" width="120">
          <template #default="scope">
            <el-tag :type="getLeaveTypeTag(scope.row.type)">
              {{ scope.row.type }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="startDate" label="开始时间" width="180" />
        <el-table-column prop="endDate" label="结束时间" width="180" />
        <el-table-column prop="status" label="状态" width="120">
          <template #default="scope">
            <el-tag :type="getStatusTag(scope.row.status)">
              {{ scope.row.status }}
            </el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="reason" label="请假原因" show-overflow-tooltip />
        <el-table-column prop="reply" label="审批意见" show-overflow-tooltip />
      </el-table>
    </el-card>

    <!-- 请假申请表单弹窗 -->
    <el-dialog
      v-model="showDialog"
      title="请假申请"
      width="50%"
    >
      <el-form :model="leaveForm" label-width="100px">
        <el-form-item label="请假类型">
          <el-select v-model="leaveForm.type">
            <el-option label="事假" value="事假" />
            <el-option label="病假" value="病假" />
            <el-option label="年假" value="年假" />
          </el-select>
        </el-form-item>
        <el-form-item label="请假时间">
          <el-date-picker
            v-model="leaveForm.dateRange"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          />
        </el-form-item>
        <el-form-item label="请假原因">
          <el-input
            v-model="leaveForm.reason"
            type="textarea"
            rows="3"
            placeholder="请输入请假原因"
          />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="showDialog = false">取消</el-button>
          <el-button type="primary" @click="submitLeave">提交</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
export default {
  name: 'LeaveApply',
  data() {
    return {
      showDialog: false,
      leaveForm: {
        type: '',
        dateRange: [],
        reason: ''
      },
      leaveRecords: [
        {
          type: '事假',
          startDate: '2024-03-20 09:00',
          endDate: '2024-03-21 18:00',
          status: '待审批',
          reason: '个人事务处理',
          reply: ''
        },
        {
          type: '病假',
          startDate: '2024-03-15 09:00',
          endDate: '2024-03-15 18:00',
          status: '已通过',
          reason: '感冒发烧',
          reply: '同意'
        }
      ]
    }
  },
  methods: {
    handleApply() {
      this.showDialog = true
    },
    submitLeave() {
      // 模拟提交
      this.$message.success('申请提交成功')
      this.showDialog = false
    },
    getLeaveTypeTag(type) {
      const types = {
        '事假': 'info',
        '病假': 'warning',
        '年假': 'success'
      }
      return types[type] || ''
    },
    getStatusTag(status) {
      const types = {
        '待审批': 'warning',
        '已通过': 'success',
        '已拒绝': 'danger'
      }
      return types[status] || ''
    }
  }
}
</script>

<style scoped>
.leave-apply {
  padding: 20px;
}

.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
</style> 